package com.nervenets.shopping.controller.common.params;

import com.nervenets.general.web.params.EntityPagingParams;
import com.nervenets.shopping.enumeration.CheckStatus;
import com.nervenets.shopping.hibernate.domain.common.IdCard;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class IdCardPagingParams extends EntityPagingParams<IdCard> {
    @ApiModelProperty(value = "关联人ID")
    private long unionId;
    @ApiModelProperty(value = "关键词")
    private String keyword;
    @ApiModelProperty(value = "审核状态，不传不筛选")
    private CheckStatus checkStatus;

    @Override
    public void generateSpecification(List<Predicate> predicates, Root<IdCard> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
        addEqualsPredicate(root.get("unionId"), unionId, unionId > 0);
        addOrLikePredicate(keyword, root.get("name"), root.get("address"), root.get("number"));
        addEqualsPredicate(root.get("checkStatus"), checkStatus, null != checkStatus);
    }
}
